<template>
<view class="container">
  <view class="form_reward_list">
    <view class="form_reward_item" v-for="(formRewardItem, index) in formRewardList" :key="index">
      <view class="form_title">
        <view class="form_title_left">
          <text class="form_type">[奖励人]</text>
          <text class="form_name">{{formRewardItem.rewardPlatformUserName}}</text>
        </view>
        <view class="form_title_right">
            <!--  "奖励类型 1积分 2红包  3优惠券 4线下奖励 5分销 {{properties.alias_yue||'余额'}}" -->
            <!-- <text class='reward_type' wx:if="{{formRewardItem.rewardType==1}}">积分</text>
            <text class='reward_type' wx:if="{{formRewardItem.rewardType==2}}">红包</text>
            <text class='reward_type' wx:if="{{formRewardItem.rewardType==3}}">优惠券</text>
            <text class='reward_type' wx:if="{{formRewardItem.rewardType==4}}">线下奖励</text>
            <text class='reward_type' wx:if="{{formRewardItem.rewardType==5}}">分销{{properties.alias_yue||'余额'}}</text>
            <text class='reward_value'>{{formRewardItem.rewardValue}}</text> -->
          <!-- <image class='user_icon' src='{{formRewardItem.rewardPlatformUserIcon}}'></image>
          <text class='user_name'>{{formRewardItem.rewardPlatformUserName}}</text> -->
        </view>
      </view>
      <view class="form_description">
        <text class="form_description_text">{{formRewardItem.rewardRemark}}</text>
        <!-- <image class='form_state_icon' wx:if="{{formRewardItem.recordStatus==1}}" src='http://image1.sansancloud.com/xianhua/2018_11/14/21/20/50_605.jpg?x-oss-process=style/preview_120'></image>
        <image class='form_state_icon' wx:if="{{formRewardItem.recordStatus==0}}" src=' http://image1.sansancloud.com/xianhua/2018_11/14/21/24/17_402.jpg?x-oss-process=style/preview_120'></image>
        <text style='color:#4bb3ff' wx:if="{{formRewardItem.recordStatus==1}}">表单有效</text>
        <text style='color:#888' wx:if="{{formRewardItem.recordStatus==0}}">表单未审核...</text> -->
      </view>
      <view class="form_reward_bottom">
        <view class="form_reward_bottom_left">
          <!-- <view class='check_record'><text>奖励记录</text></view> -->
          <text class="reward_type" v-if="formRewardItem.rewardType==1">积分</text>
          <text class="reward_type" v-if="formRewardItem.rewardType==2">红包</text>
          <text class="reward_type" v-if="formRewardItem.rewardType==3">优惠券</text>
          <text class="reward_type" v-if="formRewardItem.rewardType==4">线下奖励</text>
          <text class="reward_type" v-if="formRewardItem.rewardType==5">分销{{properties.alias_yue||'余额'}}</text>
          <text class="reward_value" v-if="formRewardItem.rewardType!=3">{{formRewardItem.rewardValue}}</text>
        </view>
        <view class="form_reward_bottom_right">
          <image class="form_reward_icon" src="http://image1.sansancloud.com/xianhua/2018_11/14/19/58/37_380.jpg?x-oss-process=style/preview_120"></image>
          <text class="form_reward_time">{{formRewardItem.rewardTime}}</text>
          <!-- <image class='form_reward_dot'src='http://image1.sansancloud.com/xianhua/2018_11/14/21/7/48_739.jpg?x-oss-process=style/preview_120'></image> -->
        </view>
      </view>
    </view>
  </view>
</view>
</template>

<script>

export default {
  data() {
    return {
      formRewardList: [],
      moneyAmount: 0,
      mendian: null,

      /**
       * 生命周期函数--监听页面加载
       */
      params: {},
      listPage: {
        page: 1,
        pageSize: 0,
        totalSize: 0,
        curpage: 1
      },
      setting: "",
      properties: ""
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    console.log('===options===', options);
    this.params = options;
    this.getData(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting,
      properties: getApp().globalData.properties
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.reflesh == 1) {
      this.onPullDownRefresh();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.Data = [];
    this.listPage.page = 1;
    this.getData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('===onReachBottom====');
    var that = this;

    if (that.listPage.totalSize > that.listPage.page * that.listPage.pageSize) {
      that.listPage.page++;
      this.getData();
    }
  },
  methods: {
    /* 获取数据 */
    getData: function () {
      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      var getParams = {bussinessType:-1};
      getParams.bussinessRecordId = this.params.bussinessRecordId;
      getParams.page = this.listPage.page;
      var customIndex = getApp().globalData.AddClientUrl("/wx_find_reward_records.html", getParams);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == 0) {
            that.listPage.pageSize = res.data.relateObj.pageSize;
            that.listPage.totalSize = res.data.relateObj.totalSize;
            let dataArr = that.formRewardList;

            if (!res.data.relateObj.result || res.data.relateObj.result.length == 0 || that.listPage.page == 1) {
              dataArr = [];
            }

            dataArr = dataArr.concat(res.data.relateObj.result);
            that.setData({
              formRewardList: dataArr
            });
          }

          console.log('===formRewardList===', that.formRewardList);
        },
        complete: function (res) {}
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>